@extends('admin.app')

@section('breadcrumb')
    <div class="bg-light lter b-b wrapper-md">
        <ol class="breadcrumb bg-light lter m-n no-padder">
            <li><a href="{{admin_action('HomeController@index')}}"> 主页</a></li>
            <li><a href="{{admin_action('Web\InformationsController@index')}}">信息模板</a></li>
            <li class="active">新增信息模板</li>
        </ol>
    </div>
@endsection

@section('content')
    <div class="panel panel-default">
        <div class="panel-heading font-bold">
            信息模板信息
        </div>
        <div class="panel-body">
            <form class="form-horizontal form-validation" action="{{ admin_action('Web\InformationsController@update',[$information]) }}" method="post">
                {{ csrf_field() }}
                {{ method_field('PUT') }}
                <div class="form-group">
                    <label class="col-lg-2 control-label">模板类型*</label>
                    <div class="col-lg-10">
                        <select name="type" id="select_template" class="form-control select2">
                            <option >-----请选择模板类型-----</option>
                            @foreach ($types as $type)
                                <option value="{{$type->code}}" {{$information->type==$type->code?'selected':''}}>{{$type->name}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <label for="inputName" class="col-sm-2 control-label">模板标题*</label>
                    <div class="col-lg-10">
                        <input name="title" type="text" class="form-control"  value="{{$information->title}}" placeholder="请输入标题名称" data-rule-required="true" data-rule-maxlength="100">
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <label class="col-lg-2 control-label">位置信息*</label>
                    <div class="col-lg-10">
                        <select name="position" class="form-control select2">
                            <option value>-----请选择信息位置-----</option>
                            @foreach ($positions as $position)
                                <option value="{{$position->code}}" {{$information->position==$position->code?'selected':''}}>{{$position->name}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <label class="col-lg-2 control-label">是否启用*</label>
                    <div class="col-lg-10">
                        <label class="radio-inline i-checks i-checks-sm">
                            <input type="radio" name="state" value="1" {{$information->state?'checked':''}}>
                            <i ></i> 是
                        </label>
                        <label class="radio-inline i-checks i-checks-sm">
                            <input type="radio" name="state" value="0" {{$information->state?'':'checked'}}>
                            <i ></i> 否
                        </label>
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <label class="col-lg-2 control-label">内容*</label>
                    <div class="col-lg-10">
                        <textarea id="ueditor_container" name="content">{!! $information->content !!}</textarea>
                        <textarea id="content_textarea" class="form-control" name="content" rows="5" data-rule-required="true" data-rule-maxlength="200" placeholder="请输入模板内容">{{$information->content}}</textarea>
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <div class="col-lg-4 col-lg-offset-2">
                        <a href="{{ admin_action('Web\InformationsController@index') }}" class="btn btn-default">返&nbsp;回</a>
                        <button type="submit" class="btn btn-primary">保&nbsp;存</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
@endsection
@section('scripts')
    @include('admin.partials.ueditor')
    <script type="text/javascript">
      $(function(){
        //初始化隐藏textarea
        if($('#select_template').find('option:selected').text() == '短信'){
          $('#ueditor_container').hide().attr('disabled','disabled');
          $('#content_textarea').show().removeAttr('disabled');
        }else{
          $('#content_textarea').hide().attr('disabled','disabled');
          $('#ueditor_container').show().removeAttr('disabled');
        }

        //改变下拉框的值判断是否使用textarea
        $('#select_template').change(function(){
          if($(this).find('option:selected').text() == '短信'){
            $('#ueditor_container').hide().attr('disabled','disabled');
            $('#content_textarea').show().removeAttr('disabled');
          }else{
            $('#content_textarea').hide().attr('disabled','disabled');

            $('#ueditor_container').show().removeAttr('disabled');
          }
        });
      });
    </script>
@endsection